package com.quan.simple.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.quan.common.properties.SmsConfigProperties;
import com.quan.common.utils.PasswordUtils;
import com.quan.sdk.sms.service.SmsService;

@RestController
public class SimpleController {

	@Autowired
	private SmsConfigProperties smsConfigProperties;

	@Autowired
	private SmsService smsService;

	@GetMapping(value = "/read")
	public Object readProperties() {
		System.out.println(this.smsConfigProperties);
		return "读取配置文件：" + this.smsConfigProperties;
	}

	@GetMapping(value = "/sendSms")
	public Object sendSms() {
		try {
			SendSmsResponse response = this.smsService.sendSmsMessage(
					"15602208451", 
					"杨浩泉", 
					"SMS_126971378",
					"{\"name\":\"Tom\", "
					+ "\"code\":\"123\"}");

			if (response.getCode() != null && response.getCode().equals("OK")) {
				return "发送成功" ;
			} else {
				return "发送失败" ;
			}
		} catch (ClientException e) {
			e.printStackTrace();
		}
		return "发送异常";
	}

	public static void main(String[] args) {
		System.out.println(PasswordUtils.encodePassword("123456", "3abb3f1a250e4cdf85cfea70a7f3f50a"));
	}
}
